package cn.kgc.ffzw.day23.QuickHit;

import java.util.Random;

public class Game {
    Player player;

    public String printStr(){

        StringBuffer stringBuffer=new StringBuffer();
        Random random=new Random();
        int length=LevelParam.list.get(player.getLevelNo()-1).getStrLength();
        for(int i=0;i< length;i++){
            int rand=random.nextInt(length);

            switch (rand){
                case 0:stringBuffer.append(">");
                break;
                case 1:stringBuffer.append("<");
                    break;
                case 2:stringBuffer.append("*");
                    break;
                case 3:stringBuffer.append("&");
                    break;
                case 4:stringBuffer.append("%");
                    break;
                case 5:stringBuffer.append("#");
                    break;
            }
        }
        return String.valueOf(stringBuffer);
    }

    public void printResult(String out,String in){

        long currentTime = System.currentTimeMillis();

        player.setElapsedTime((int) ((currentTime-player.getStartTime())/1000));

        if(player.getElapsedTime()>LevelParam.list.get(player.getLevelNo()-1).getTimeLimit()){
            System.out.println("你输入太慢了，已经超时，退出");
            System.exit(1);
        }

        if(in.equals(out)){
            player.setCurrScore(player.getCurrScore()+LevelParam.list.get(player.getLevelNo()-1).getPerScore());
            System.out.println("输入正确，您的积分为"+player.getCurrScore()+",您的级别是"+player.getLevelNo()+",已用时间为"+ player.getElapsedTime()+"秒");
        }else{
            System.out.println("输入错误，游戏结束！！！");
            System.exit(1);
        }

    }

    public void setPlayer(Player player) {
        this.player = player;
    }

}
